<?php
$GLOBALS['PAGE_FORM_DATA'] = array();
$act = isset($_REQUEST['act'])?$_REQUEST['act']:'';
$dt = new DataTable(constant('DB_TABLE_PRODUCT'));
$GLOBALS['GV_IMAGE_PATH'] = 'product/';
if ( $act == 'save') {
	$product_data = $_REQUEST;
	
	if ( strlen($product_data['ajaxf_image']) > 0) {
		$GLOBALS['APP_INSTANCE']->saveUploadedFile($product_data['ajaxf_image'], $GLOBALS['GV_IMAGE_PATH'] );
		$product_data['img_path'] = $product_data['ajaxf_image'];
	}
	$dt->save($product_data);
	ob_clean();
	$redirect_url = 'products.php';
	$redirect_url .= '?cat_id='.$product_data['cat_id'];
	header('Location:'.$redirect_url);
	exit();
}
else if ( $act == 'edit') {
	$GLOBALS['PAGE_FORM_DATA'] = $dt->get(intval($_REQUEST['id']));
}
else{
	$GLOBALS['PAGE_FORM_DATA'] = $_REQUEST;
	$GLOBALS['PAGE_FORM_DATA']['id'] = 0;
	if ( !isset($GLOBALS['PAGE_FORM_DATA']['cat_id']) )
		$GLOBALS['PAGE_FORM_DATA']['cat_id'] = 0;
	$GLOBALS['PAGE_FORM_DATA']['name'] = '';
	$GLOBALS['PAGE_FORM_DATA']['content'] = '';
	$GLOBALS['PAGE_FORM_DATA']['price'] = '';
	$GLOBALS['PAGE_FORM_DATA']['image_path'] = false;
	
}
?>